package an_lexico;

import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;

/**
 *
 * @author fernando
 */
public class Token {

    /**
     * Undefined type of token.
     */
    public static final int Type_EOF = 0,  Undefined = -1;


    /**
     * ID of the token.
     */
    String ID;

    /**
     * Type of the token.
     */
    int tokenType;

    /**
     * Set type of token as undefined.
     */
    public Token() {
        this.tokenType = Undefined;
    }

    /**
     * Set type of token.
     *
     * @param ID ID of the token
     */
    public Token(char[] ID) {
        this.ID = new String(ID);
        this.tokenType = Undefined;
    }

    /**
     * Set ID
     *
     * @param ID ID of the token
     */
    public Token(String ID) {
        this.ID = ID;
    }

    /**
     * Set type of token
     *
     * @param ID ID of the token
     * @param tokenType Type of the token
     */
    public Token(char[] ID, int tokenType) {
        this.ID = new String(ID);
        this.tokenType = tokenType;
    }

    /**
     * Set type of token
     *
     * @param ID ID of the token
     * @param tokenType Type of the token
     */
    public Token(String ID, int tokenType) {
        this.ID = ID;
        this.tokenType = tokenType;
    }

    /**
     * Extract the token type
     *
     * @return tokenType Type of the token
     */
    public int getTokenType() {
        return tokenType;
    }

    /**
     * Set type of token
     *
     * @param tokenType Type of the token
     */
    public void setTokenType(int tokenType) {
        this.tokenType = tokenType;
    }

    /**
     * Extract ID
     *
     * @return ID ID of the token
     */
    public String getID() {
        return ID;
    }

    /**
     * Set ID of the token
     *
     * @param ID ID of the token
     */
    public void setID(String ID) {
        this.ID = ID;
    }

    /**
     * Set ID of the token
     *
     * @param ID ID of the token
     */
    public void setID(char[] ID) {
        this.ID = new String(ID).trim();
    }

    /**
     * Compare if tokens are equals
     *
     * @param Object Token
     * @return boolean
     */
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Token) {
            Token t = (Token) obj;
            if (this.ID.equals(t.ID) && this.tokenType == t.tokenType) {
                return true;
            }
        }
        return false;
    }

    /**
     * hashCode
     *
     * @return hash
     */
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 41 * hash + (this.ID != null ? this.ID.hashCode() : 0);
        hash = 41 * hash + this.tokenType;
        return hash;
    }
}
